package com.ailink.foodshop.service.impl;

import com.ailink.foodshop.dto.OrderDTO;
import com.ailink.foodshop.service.PushMessageService;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/1/12
 */
@Service
public class PushMessageServiceImpl implements PushMessageService {

//    @Autowired
//    private WxMpService wxMpService;

    @Override
    public void orderStatus(OrderDTO orderDTO) {
        //Cookie: openid=o97tn1TR6883y7GKzEiwBSGo9g0w
        WxMpTemplateMessage wxMpTemplateMessage = new WxMpTemplateMessage();
        wxMpTemplateMessage.setTemplateId("qX60lHH9kwgwtNu27AcQiBtFs9KSU_VV96n9TyuvxzU");
        //接收消息者的openid
        wxMpTemplateMessage.setToUser("o0-hAuPGl3CN0iv--IVlKSATkRnI");

//        List<WxMpTemplateData> data = Arrays.asList(
//                new WxMpTemplateData("first","亲！记得收货！"),
//                new WxMpTemplateData("keyword1","微信点餐"),
//                new WxMpTemplateData("keyword2","12122223334"),
//                new WxMpTemplateData("keyword3",orderDTO.getBuyerOpenid()),
//                new WxMpTemplateData("keyword4",orderDTO.getOrderStatusEnums().getMsg()),
//                new WxMpTemplateData("keyword5","$"+orderDTO.getOrderAmount()),
//                new WxMpTemplateData("remark","欢迎再次光临！")
//        );
//        wxMpTemplateMessage.setData(data);
        WxMpService wxMpService = new WxMpServiceImpl();
        try {
            wxMpService.getTemplateMsgService().sendTemplateMsg(wxMpTemplateMessage);
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
    }
}
